/*
 * @Author: your name
 * @Date: 2023-11-17 15:26:41
 * @LastEditTime: 2024-04-08 14:22:43
 * @LastEditors: wen www.lz13100719336@163.com
 * @Description: 
 */
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import qiankun from 'vite-plugin-qiankun'
function log(label: any, content: any) {
  console.log("\x1b[1m%s\x1b[31m%s\x1b[0m", label, content);
}

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  // const env = loadEnv(mode, process.cwd(), './env')
  const env = loadEnv(mode, fileURLToPath(new URL('./env', import.meta.url)))
  log('api: ', env.VITE_APP_API_URI_PROXY_DEV)
  return {
    base: './',
    envDir: path.resolve(__dirname, './env'),
    plugins: [
      vue(),
      qiankun('vue3-1',{
        useDevMode: true
      })
    ],
    server: {
      // port: 3000,
      host: '0.0.0.0',
      headers: {
        "Access-Control-Allow-Origin": "*",
      },
      proxy: {
        "^/api/": {
          target: env.VITE_APP_API_URI_PROXY_DEV,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '/'),
        },
      }
    },
    css: {
      // css预处理器
      preprocessorOptions: {
        scss: {
          // 引入 mixin.scss 这样就可以在全局中使用 mixin.scss中预定义的变量了
          // 给导入的路径最后加上 ;  
          additionalData:   "@import '@/assets/style/utils.scss';@import '@/assets/style/element/resetElement.scss';",
        }
      }
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
      }
    }
  }
})
